<?php
class action extends mysql{
	
	//获取两个不同的随机数，需要先产生一个随机数$num
	/* function differNum($num,$min,$max){
		$rand = rand($min,$max);
		return(($num == $rand)?differNum($num,$min,$max):$rand);
	} */
	
	/**Elo排名算法
	 * 
	 * $ra     选手a的当前排名得分
	 * $rb     选手b的当前排名得分
	 * $awin   表示选手a是否胜出，胜得1分，输0分
	 * $k      为常数，数值越大比分变动越快，默认设置为5
	 * $result 结果以数组形式返回
	 *
	 */
	function eloRank($ra,$rb,$awin,$k=5){
		($awin == 0)?$awin=0:$awin=1;                //强制输入不为0时，变为1分
		$ea = 1/(1+pow(10,($rb-$ra)/400));           //选手a的期望
		$eb = 1/(1+pow(10,($ra-$rb)/400));           //选手b的期望
		$result[0] = $ra + $k * ( $awin - $ea );     //选手a的得分
		$result[1] = $rb + $k * ( (1-$awin) - $eb ); //选手b的得分
		return $result;
	}
	
	function is_login($session,$url){
		if(!isset($_SESSION[$session])){
			$this->jumpAction($url,"请先登录");
		}
	}

	function jumpAction($url,$msg='操作成功'){
		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml">
				<head>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
				<meta name="keywords" content="facemash"><!--SEO关键字-->
				<meta name="description" content=""><!--SEO描述-->
				<meta http-equiv="refresh" content="2;URL='.$url.'"><!--自动跳转-->
				<link rel ="" href=""><!--选项卡图标-->
				<title>Facemash | Huanu</title>
				<link rel="stylesheet" href="../templates/css/base.css">
				<link rel="stylesheet" href="../templates/css/common.css">
				<link rel="stylesheet" href="../templates/css/page.css">
				<!--[if ie 6]>
				<link rel="stylesheet" href="../templates/css/ie6.css">
				<![endif]-->
				</head>
				
				<body>
					<div id="header" class="tc cf h150"><!-- header -->
						<h1 class="f80 h80 logo">Facemash</h1>
						<p class="f24 mt5">选出你心目中的女神（湖南农大专场）</p>
						<div id="nav" class="mt15">
							<a href="index.php" class="cf p10">美女大PK</a>
							<a href="rank.php" class="cf p10">排行榜</a>
							<a href="report.php" class="cf p10">打假</a>
							<a href="about.php" class="cf p10">关于</a>
						</div>
					</div><!-- end_header -->
					<div id="main" class="w960 bc oh h300 mt50 c6 tc"><!-- main -->
						<p class="f24 mt100">'.$msg.'</p>
					</div><!-- end_main -->
					<div id="footer" class=" tc w960 bc c9 mt20 pb20"><!-- footer -->
						<p>&copy;2012 Hunau_Jinan</p>
					</div><!-- end_footer -->
				</body>
				</html>';
		exit();
	}
}
?>